
#
# Author : itech
# 

import os.path
import datetime
import Common

def DataAndTimeId():
    dt = datetime.datetime.now()
    d = dt.date()
    t = dt.time()
    buildid = d.strftime("%m%d%Y") + "." + t.strftime("%H%M%S")
    return buildid

def GetBuildIdByDataAndTime(idtype='DataAndTimeId', buildidfile='buildid.txt', existed = '0'):

    if existed == '1':
      try :
        return Common.OpenFile(buildidfile)
      except Exception as e :
        print e
        return ''

      buildid = ''
    if idtype == 'DataAndTimeId':
      buildid = DataAndTimeId()

    Common.WriteFile(buildidfile,buildid)
    
    return  buildid
    
def Usage() :
    print """
    Usage :
    python BuildId.py [buildidtype buildidfile existed]    
    Example : 
    python BuildId.py DataAndTimeId buildid.txt 0
    """

def Main(argv) :
    if len(argv) == 3 :
        buildid = GetBuildIdByDataAndTime(argv[0],argv[1],argv[2])
        print buildid
        return buildid
    else : 
        Usage()

if __name__ == "__main__" :
    import sys
    Main(sys.argv[1:])